package com.module.flowLine.manager;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import base.dao.GenericHibernateDao;
import base.manager.GenericHibernateManager;
import com.module.flowLine.vo.SktException;

/**
 * 流水线预警管理类
 * 
 * @author DELL
 * 
 */
public class SktExceptionManager extends
		GenericHibernateManager<SktException, Long> {

	private static SktExceptionManager service;

	public synchronized static SktExceptionManager getInstance() {
		if (service == null) {
			service = new SktExceptionManager();
		}
		return service;
	}

	/**
	 * 
	 * 获取流水线预警信息
	 * 
	 * @param session
	 * @param key
	 * @param value
	 * @return
	 * @throws Exception 
	 */
	public List getFlowLineExceptionList(String key, String value) throws Exception {
		try {
			Session session = this.getSession();
			String hsql = " from SktException where " + key + "='" + value
					+ "'";
			Query query = session.createQuery(hsql);
			return query.list();
		} catch (Exception ex) {
			throw ex;
		}finally{
			this.closeSession();
		}
		
	}
	
	public List getFlowLineExceptionList(SktException vo) throws Exception{
		try {
			Session session = this.getSession();
			String cond = "1=1";
			//级别
			if(vo.getAlarmlevel()!=null && !"".equals(vo.getAlarmlevel()))
				cond += " and alarmlevel='"+vo.getAlarmlevel()+"'";
			//状态
			if(vo.getStatus()!=null)
				cond += " and status='"+vo.getStatus()+"'";
			String hsql = " from SktException where " + cond;
			Query query = session.createQuery(hsql);
			return query.list();
		} catch (Exception ex) {
			throw ex;
		}finally{
			this.closeSession();
		}
		
	}

	@Override
	public GenericHibernateDao<SktException, Long> getDao() {
		// TODO Auto-generated method stub
		return null;
	}
}
